package fms.models;
 
import java.util.List;
 
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import fms.classes.BookkeepersCashAdvanceRegister;
 
 
public class BookkeepersCashAdvanceRegisterDAO {
 
    private SqlSessionFactory sqlSessionFactory;
 
    public BookkeepersCashAdvanceRegisterDAO(){
    	try{
    		sqlSessionFactory = MyBatisSqlConnection.getSqlSessionFactory();
    	}catch(Exception e) {
    		System.out.println("failed to get sqlSessionFactory");
    	}
    }
 
    /**Returns the list of all BookkeepersCashAdvanceRegister instances from the database*/
    @SuppressWarnings("unchecked")
    public List<BookkeepersCashAdvanceRegister> selectAll(){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            List<BookkeepersCashAdvanceRegister> list = session.selectList("BookkeepersCashAdvanceRegister.getAll");
            return list;
        } finally {
            session.close();
        }
    }
 
    /**Returns a BookkeepersCashAdvanceRegister instance from the database*/
    public BookkeepersCashAdvanceRegister selectById(int entry_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            BookkeepersCashAdvanceRegister BKCashAdvanceReg = (BookkeepersCashAdvanceRegister) session.selectOne("BookkeepersCashAdvanceRegister.getById", entry_no);
            return BKCashAdvanceReg;
        } finally {
            session.close();
        }
    }
    
    /**Returns a BookkeepersCashAdvanceRegister instance from the database
    public BookkeepersCashAdvanceRegister getAllPending(String status){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            BookkeepersCashAdvanceRegister BKCashAdvanceReg = (BookkeepersCashAdvanceRegister) session.selectOne("BookkeepersCashAdvanceRegister.getAllPending", status);
            return BKCashAdvanceReg;
        } finally {
            session.close();
        }
    }*/
 
    /**Updates an instance of BookkeepersCashAdvanceRegister in the database*/
    public void update(BookkeepersCashAdvanceRegister BKCashAdvanceReg){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.update("BookkeepersCashAdvanceRegister.update", BKCashAdvanceReg);
            session.commit();
        } finally {
            session.close();
        }
    }
    
    /**Updates the status of BookkeepersCashAdvanceRegister in the database
    public void updateStatus(int entry_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.update("BookkeepersCashAdvanceRegister.updateStatus", entry_no);
            session.commit();
        } finally {
            session.close();
        }
    }*/
 
    /** Insert an instance of BookkeepersCashAdvanceRegister into the database*/
    public void insert(BookkeepersCashAdvanceRegister BKCashAdvanceReg){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.insert("BookkeepersCashAdvanceRegister.insert", BKCashAdvanceReg);
            session.commit();
        } finally {
            session.close();
        }
    }
 
    /** Delete an instance of BookkeepersCashAdvanceRegister from the database*/
    public void delete(int entry_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.delete("BookkeepersCashAdvanceRegister.deleteById", entry_no);
            session.commit();
        } finally {
            session.close();
        }
    }
}